package service

import (
	sqlc "bgs/db/sqlc"
)

// CheckNeedProfitShare 订单是否需要分账
func CheckNeedProfitShare(orderPtr *sqlc.Order) bool {
	return orderPtr.NeedProfitToPlatformCommission || orderPtr.NeedProfitToDistributeCommission || orderPtr.NeedProfitToBonus
}

// CheckNeedRefundShippingFee 订单是否需要退运费
func CheckNeedRefundShippingFee(orderPtr *sqlc.Order) bool {
	return orderPtr.ShippingFee > 0 && (orderPtr.OrderStatus == string(sqlc.EmOrderStatusDelivered) ||
		orderPtr.OrderStatus == string(sqlc.EmOrderStatusPrepared) ||
		orderPtr.OrderStatus == string(sqlc.EmOrderStatusFinished))
}

// CheckIsOrderComplete 订单是否已经完结
func CheckIsOrderComplete(orderPtr *sqlc.Order) bool {
	return (orderPtr.OrderStatus == string(sqlc.EmOrderStatusFinished) ||
		orderPtr.OrderStatus == string(sqlc.EmOrderStatusBeforePayClosed) ||
		orderPtr.OrderStatus == string(sqlc.EmOrderStatusAfterPayClosed))
}

// CheckIsOrderFinish 订单是否完成
func CheckIsOrderFinish(orderPtr *sqlc.Order) bool {
	return orderPtr.OrderStatus == string(sqlc.EmOrderStatusFinished)
}

// 对下面公式的前提:这里假定售后单和订单都已经更新完毕 vip
func CalcUnsplitAmount(orderPtr *sqlc.Order) (unSplitAmount int64) {
	// 实际未分配金额=订单实付金额+订单的微信服务费(<0)+已退金额(<0)]
	unSplitAmount = orderPtr.ActualAmount + orderPtr.WxpayCommissionAmount + orderPtr.RefundAmount
	return
}
